package com.isesol.ime.validator.param;

import com.isesol.arch.fluentvalidator.*;
import com.isesol.ime.dal.mapper.*;
import com.isesol.ime.dal.model.dto.*;
import com.isesol.ime.enums.*;
import org.springframework.stereotype.*;

import javax.annotation.*;

@Component
public class ParamDeleteValidator extends ValidatorHandler<ParamDTO> implements Validator<ParamDTO>{

	@Resource
	ParamMapper paramMapper;

	@Override
	public boolean validate(ValidatorContext context, ParamDTO paramDTO){

		if (null == paramDTO.getId()){

			context.addErrorMsg("id is null");

			return false;
		}

		if (null == paramMapper.getById(paramDTO.getId())){

			context.addErrorMsg(ErrorCode.ID_INVALID.getMessage());

			return false;
		}

		return true;
	}
}
